export const schema = {
    type: "page",
    title: "模块管理",
    toolbar: {
        type: "button",
        icon: "fa fa-plus pull-left",
        level: "success",
        label: "新建模块",
        actionType: "dialog",
        dialog: {
            title: "",
            body: {
                type: "form",
                api: "post:/api/module",
                tabs: [
                    {
                        title: "基本信息",
                        controls: [
                            {
                                type: "text",
                                name: "key",
                                label: "标识",
                                desc: "模块唯一标识",
                                required: true
                            },

                            {
                                type: "text",
                                name: "label",
                                label: "按钮名称",
                                required: true
                            },

                            {
                                type: "image",
                                name: "icon",
                                label: "按钮图标",
                                required: true
                            },

                            {
                                type: "switch",
                                name: "optional",
                                value: true,
                                label: "是否可选",
                                desc: "如果勾选说明，机构用户可自由决定是否启用此模块"
                            }
                        ]
                    },

                    {
                        title: '配置项',
                        controls: [
                            {
                                label: false,
                                type: 'combo',
                                disabled: true,
                                name: 'settings',
                                multiple: true,
                                value: [
                                    {
                                        key: 'label',
                                        label: '名称',
                                        type: 'text'
                                    },

                                    {
                                        key: 'icon',
                                        label: 'Icon',
                                        type: 'image'
                                    },

                                    {}
                                ],
                                controls: [
                                    {
                                        type: 'text',
                                        name: 'key',
                                        placeholder: '字段名'
                                    },

                                    {
                                        type: 'text',
                                        name: 'label',
                                        placeholder: '显示名称'
                                    },

                                    {
                                        type: 'select',
                                        name: 'type',
                                        placeholder: '配置项类型',
                                        options: [
                                            {
                                                value: 'text',
                                                label: '文本输入'
                                            },

                                            {
                                                value: 'image',
                                                label: '图片上传'
                                            }
                                        ]
                                    }
                                ],
                                desc: '机构启用此模块时，可以用来设置的配置项'
                            }
                        ]
                    }
                ]
            }
        }
    },
    body: {
        type: "crud",
        api: "get:/api/module",
        columnsTogglable: false,
        showHeader: false,
        columns: [
            {
                name: "key",
                label: "模块标识"
            },

            {
                name: "label",
                label: "按钮名称"
            },

            {
                name: "icon",
                label: "Icon",
                type: 'image'
            },

            {
                name: "optional",
                label: "是否可自定义",
                type: 'map',
                map: {
                    '*': "<span class='label label-default'>否</span>",
                    '1': "<span class='label label-success'>是</span>"
                }
            },

            {
                label: "操作",
                type: "operation",
                width: 180,
                buttons: [
                    {
                        type: "button",
                        size: "xs",
                        level: "info",
                        label: "编辑",
                        actionType: "dialog",
                        dialog: {
                            title: "",
                            body: {
                                type: "form",
                                api: "put:/api/module/${id}",
                                tabs: [
                                    {
                                        title: "基本信息",
                                        controls: [
                                            {
                                                type: "text",
                                                name: "key",
                                                label: "标识",
                                                desc: "模块唯一标识",
                                                disabled: true
                                            },

                                            {
                                                type: "text",
                                                name: "label",
                                                label: "按钮名称",
                                                required: true
                                            },

                                            {
                                                type: "image",
                                                name: "icon",
                                                label: "按钮图标",
                                                required: true
                                            },

                                            {
                                                type: "switch",
                                                name: "optional",
                                                label: "是否可选",
                                                desc: "如果勾选说明，机构用户可自由决定是否启用此模块"
                                            }
                                        ]
                                    },

                                    {
                                        title: '配置项',
                                        controls: [
                                            {
                                                label: false,
                                                type: 'combo',
                                                name: 'settings',
                                                multiple: true,
                                                disabled: true,
                                                controls: [
                                                    {
                                                        type: 'text',
                                                        name: 'key',
                                                        placeholder: '字段名'
                                                    },

                                                    {
                                                        type: 'text',
                                                        name: 'label',
                                                        placeholder: '显示名称'
                                                    },

                                                    {
                                                        type: 'select',
                                                        name: 'type',
                                                        placeholder: '配置项类型',
                                                        options: [
                                                            {
                                                                value: 'text',
                                                                label: '文本输入'
                                                            },

                                                            {
                                                                value: 'image',
                                                                label: '图片上传'
                                                            }
                                                        ]
                                                    }
                                                ],
                                                desc: '机构启用此模块时，可以用来设置的配置项'
                                            }
                                        ]
                                    }
                                ]
                            }
                        }
                    }
                ]
            }
        ]
    }
};
